

local info = {
    --'自动合成',
    --'自动整理',
    --'物品绑定',
    '伤害显示',
    '友伤显示',
    '自动施法',
    --'智能施法',
}
local tips = {
    ['自动合成'] = '开启“自动整理”每隔10秒自动合成一次',
    ['自动整理'] = '开启“自动整理”每隔10秒整理一次',
    ['物品绑定'] = function(player)
        player._gxzb = not player._gxzb
        if player._gxzb then
            player:warning('物品锁解除，别的玩家可以拾取你的物品！')
        else
            player:warning('物品锁开启，别的玩家不可以拾取你的物品！')
        end
    end,
}
ac.wait(100,function()

    ac.each_player(function(player)
        player:set_data('开关-伤害显示',true)
        player:set_data('开关-自动施法',true)
        player:set_data('开关-物品绑定',true)
    end)
    ac.game:notify('游戏-刷新开关设置')
    
end)
local w,h = 120,32
local init_x = 1860
local buttons = {}
for a,name in ipairs(info) do
    buttons[a] = class.button:builder
    {
        x = init_x,
        y = 600 + (a-1)*h,
        w = w,
        h = h,
        name = name,
        sync_key = name,
        back = {
            type = 'panel',
            fdf = 'tooltip_backdrop1',
            level = 1,
        },
        title = {
            type = 'text',
            x = 30,
            w = w-30,
            text = name,
            font_size = 10,
            justH = "CENTER",
            justV = "MIDDLE",
            level = 2,
        },
        icon = {
            type = 'panel',
            w = h,
            h = h,
            normal_image = [[ui\小框.tga]],
            level = 2,
        },
        open = {
            type = 'panel',
            x = 5,
            y = 5,
            w = h-10,
            h = h-10,
            normal_image = [[ui\打勾.tga]],
            level = 3,
        },
        on_button_mouse_enter = function(self,button)
            if self.active_timer then
                self.active_timer:remove()
            end
            self.active_timer = ac.loop(30, function (t)
                self.x = self.x - 10
                if self.x>1920 - self.w then
                    self:set_position(self.x,self.y)
                else
                    t:remove()
                    self:set_position(1920 - self.w,self.y)
                end
            end)
            self.active_timer:on_timer()
        end,
        on_button_mouse_leave = function(self)
            if self.active_timer then
                self.active_timer:remove()
            end
            self.active_timer = ac.loop(30, function (t)
                self.x = self.x + 10
                if self.x<init_x then
                    self:set_position(self.x,self.y)
                else
                    t:remove()
                    self:set_position(init_x,self.y)
                end
            end)
            self.active_timer:on_timer()
        end,
        on_button_clicked = function (self,player)
            ac.sync('游戏-设置开关',self.name)
        end,
        update = function(self)
            local player = ac.player.self
            if player:get_data('开关-'..self.name) then
                self.open:show()
            else
                self.open:hide()
            end
        end,
    }
end

ac.sync:event '游戏-设置开关'(function(_,player,name)
    local key = '开关-'..name
    local func = tips[name]
    local open = player:get_data(key)
    player:set_data(key,not open)
    if func then
        if type(func)=='string' then
            if not open then
                player:send_msg(func)
            end
        else
            func(player)
        end
    end
    ac.game:notify('游戏-刷新开关设置')
end)

ac.game:event '游戏-刷新开关设置'(function()
    for _,button in ipairs(buttons) do
        button:update()
    end
end)
ac.game:notify('游戏-刷新开关设置')